<!--
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<mat-menu #actions="matMenu"
          [classList]="'kd-user-panel'">
  <div class="kd-auth-status kd-muted"
       [ngClass]="loginStatus?.headerPresent ? 'kd-auth-header' : ''">
    <ng-container *ngIf="isLoginStatusInitialized">
      <div *ngIf="hasUsername"
           fxFlex
           fxLayout="row">
        <div fxFlex
             fxFlexAlign=" center"
             class="username">{{ username }}</div>

        <button mat-icon-button
                matTooltip="Close"
                i18n-matTooltip
                (click)="close()">
          <mat-icon class="kd-muted">arrow_drop_up</mat-icon>
        </button>
      </div>

      <div *ngIf="!hasUsername"
           fxFlex
           fxLayout="row"
           [ngSwitch]="true">
        <div fxFlex
             fxFlexAlign=" center"
             class="method">
          <ng-container *ngSwitchCase="loginStatus.headerPresent && !loginStatus.impersonationPresent"
                        i18n>Logged in with auth header
          </ng-container>
          <ng-container *ngSwitchCase="loginStatus.tokenPresent"
                        i18n>Logged in with token </ng-container>
          <ng-container *ngSwitchCase="loginStatus.headerPresent && loginStatus.impersonationPresent">{{ loginStatus.impersonatedUser }}</ng-container>
          <ng-container *ngSwitchDefault
                        i18n>Default service account </ng-container>
        </div>

        <button mat-icon-button
                matTooltip="Close"
                i18n-matTooltip
                (click)="close()">
          <mat-icon class="kd-muted">arrow_drop_up</mat-icon>
        </button>
      </div>
    </ng-container>
  </div>
  <mat-divider *ngIf="!loginStatus?.headerPresent"></mat-divider>
  <button mat-menu-item
          *ngIf="isAuthSkipped()"
          (click)="logout()"
          i18n>Sign in</button>
  <button mat-menu-item
          *ngIf="isLoggedIn()"
          (click)="logout()"
          i18n>Sign out</button>
</mat-menu>

<button mat-icon-button
        color="primary"
        [matMenuTriggerFor]="actions"
        (click)="$event.stopPropagation()">
  <mat-icon class="kd-user-panel-icon kd-primary-toolbar-icon">account_circle</mat-icon>
  <svg class="kd-cross-style"
       *ngIf="isAuthSkipped()"
       width="40px"
       height="40px"
       viewBox="0 0 40 40">
    <line class="kd-cross-outline"
          x1="10"
          x2="30"
          y1="10"
          y2="30" />
    <line class="kd-cross-line-primary"
          x1="10"
          x2="30"
          y1="10"
          y2="30" />
  </svg>
</button>
